Skip to content

Reduce per-row overhead in session recv and putValue dispatch#195

Open
TheDistributor wants to merge 1 commit into
masterfrom
mgallwey/accelerate-network-io
Open

Reduce per-row overhead in session recv and putValue dispatch#195
TheDistributor wants to merge 1 commit into
masterfrom
mgallwey/accelerate-network-io

Conversation

@TheDistributor

@TheDistributor TheDistributor commented Jun 29, 2026

Copy link
Copy Markdown
  • session.recv/__readFully: pre-allocate the receive buffer and fill it with
    recv_into, and drop the redundant bytes->bytearray copy in _exchangeMessages
  • raise the socket receive buffer to 1 MiB so large result batches arrive in
    fewer reads
  • putValue: check the common parameter types (int, str, float, bool) with a
    direct type check before falling through to the slower isinstance chain
  • executebatch: read parameter_count once instead of on every row

Nominal performance change on its own, but lays the groundwork for future changes.

Streamline the data-ingestion pipeline and outbound parameter encoding loop by
eliminating high-overhead memory copies, optimizing primitive type comparisons,
and increasing TCP window throughput.

Detailed changes:
- session: Request an opportunistic 1 MiB socket receive buffer (SO_RCVBUF) to
  minimize fragmented kernel reads across heavy wire payload streams.
- session: Rewrite `__readFully` to pre-allocate a single message-sized
  bytearray. Populate it directly using zero-copy `sock.recv_into()` on a
  slicing memoryview, replacing an iterative chunk concatenation loop.
- encodedsession: Update `recv()` and input stream targets to return and use
  raw mutable bytearray buffers directly, cutting down an extra copy.
- encodedsession: Refactor `putValue` to use rapid pointer-level exact type
  comparisons (`type(v) is X`) for common database primitives (int, str, float,
  bool) before falling back to heavier hierarchy-aware `isinstance()` checks
  for the long tail.
@TheDistributor TheDistributor self-assigned this Jun 29, 2026
@TheDistributor TheDistributor changed the title Optimize network I/O buffering and parameter type dispatch Optimize network reads in the session to generate a contiguous bytearray Jun 29, 2026
@TheDistributor TheDistributor changed the title Optimize network reads in the session to generate a contiguous bytearray Reduce per-row overhead in session recv and putValue dispatch Jun 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant